package com.mask.serviceverificationcode.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * ClassName SwaggerConfig
 * Create by hx
 * Date 2021/8/7 4:06 下午
 */

@Configuration
@EnableSwagger2  //开启Swagger2
public class SwaggerConfig {

    private static final Contact DEFAULT_CONTACT = new Contact("mask", "mask-hx.com", "2500130018@qq.com");

//    @Bean
//    public Docket docketA(){
//        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
//    }
//
//    @Bean
//    public Docket docketB(){
//        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
//    }



    //配置Swagger的Docket的bean实例
    @Bean
    public Docket docket(Environment environment){

        //设置要显示的swagger环境
        //Profiles profiles = Profiles.of("dev","pro");

        //获取项目的环境,获取environment.acceptsProfiles判断是否处在自己设定的环境当中
        //boolean flag = environment.acceptsProfiles(profiles);


        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("mask-hx")
                //enable是否启动swagger，为false则swagger不能在浏览器中访问
                //.enable(flag)
                .select()
                //配置要扫描接口的方式
                //basePackage扫描指定的包
                .apis(RequestHandlerSelectors.basePackage("com.mask.serviceverificationcode.controller"))
                //paths过滤路径
//                .paths(PathSelectors.ant("com.mask.test"))
                .build()
                ;
    }

    //配置swagger信息apiInfo
    public ApiInfo apiInfo(){
      return new ApiInfo(
              "MASK SwaggerAPI",
              "Api Documentation",
              "v1.0",
              "http://www.mask-hx.com",
              DEFAULT_CONTACT,
              "Apache 2.0",
              "http://www.apache.org/licenses/LICENSE-2.0",
              new ArrayList());

    }

}
